//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#define _NO_INCLIST
#include <eltypes.h>
#include <elasys_server.h>
#include <interlocked.h>
#include <driver.h>
//#include <stdio.h>
//#include <_pubcrt.h>
//#include <eventman.h>

#define kprintf printf
#define  PHYSADDR(addr)  addr
#define g_pDefaultScheduleClass NULL
#define g_uDefaultSchedulePolicy NULL
#define PAGE_SIZE                       4096
#define _MAX_FNAME                      256

void DzSleep(uint_t uTicks, WaitResult *pResult);

#define KCONFIG_NUMBEROF_ORDERS         10
#define c_uNumberOfOrders  KCONFIG_NUMBEROF_ORDERS

void *DzAllocKernelPages(uint_t uOrder);

void DzFreeKernelPages(virtaddr_t va, uint_t uOrder);

EXTERN void DzGetSystemTime(SystemTime *pSystemTime);

interface IStub;

EXTERN ECode DzRegisterService(
        const wchar_t *pwszServiceName, PInterface pObj, IStub **ppIStub);

EXTERN ECode DzUnregisterService(const wchar_t *pwszName, IStub *pIStub);

EXTERN ECode DzFindService(const wchar_t *pwszName, PInterface *ppObj);

typedef Int32 (CDECL *threadroutine_t)(void *);

EXTERN ECode DzCreateKernelThread(
        threadroutine_t threadroutine, void *pvArg, UInt32 dwFlags,
        ThreadPriorityRank priorityRank, IThread **ppThread);

EXTERN_C void * Drv_AllocBuffer(unsigned int uPages, unsigned int uFlag);
EXTERN_C void Drv_FreeBuffer(void * VirtAddr, unsigned int uPages);

EXTERN ECode DzIoRemap(
         Address virtualAddr,
         MemorySize size,
         Address physicalAddr,
         MemoryMapFlags flags,
         MemoryProtection protection,
         Address *pVirtualAddr);

EXTERN ECode DzIoUnmap(
         Address baseAddr,
         MemorySize size);

EXTERN ECode DzCreateEventObj(
         Boolean manualReset,
         EventState initialState,
         IEvent **ppEvent);
EXTERN IThread *CreateSystemThread(
        threadroutine_t threadroutine, void *pvParameter,
        void *pScheduleClass, uint_t uSchedulePolicy);
EXTERN UInt32 DzTicksToMilliseconds(UInt32 time);
EXTERN UInt32 DzGetElapsedTicks();

EXTERN_C ECode __cdecl OpenShareMem(unsigned long id, Address *pShareAddr);
EXTERN_C ECode __cdecl FreeOpenShareMem(Address ShareAddr);
EXTERN_C ECode __cdecl AllocShareMem(MemorySize size,MemoryProtection protection,Address *pShareAddr,unsigned long *pId);
EXTERN_C ECode __cdecl FreeAllocShareMem(Address ShareAddr);
EXTERN_C ECode __cdecl ConvertAllocAddrToId(Address ShareAddr,unsigned long offset, unsigned long *pId);
